package com.example.managemyself.ui.admin.dashboard;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.example.managemyself.R;
import com.google.android.material.card.MaterialCardView;

import java.util.List;

/**
 * 仪表板卡片适配器
 */
public class DashboardCardAdapter extends RecyclerView.Adapter<DashboardCardAdapter.ViewHolder> {
    
    private List<AdminDashboardFragment.DashboardCard> cards;
    
    public DashboardCardAdapter(List<AdminDashboardFragment.DashboardCard> cards) {
        this.cards = cards;
    }
    
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_dashboard_card, parent, false);
        return new ViewHolder(view);
    }
    
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        AdminDashboardFragment.DashboardCard card = cards.get(position);
        
        holder.tvTitle.setText(card.getTitle());
        holder.tvContent.setText(card.getContent());
        holder.ivIcon.setImageResource(card.getIconRes());
        
        // 设置卡片颜色
        int color = ContextCompat.getColor(holder.itemView.getContext(), card.getColorRes());
        holder.cardView.setCardBackgroundColor(color);
    }
    
    @Override
    public int getItemCount() {
        return cards.size();
    }
    
    static class ViewHolder extends RecyclerView.ViewHolder {
        MaterialCardView cardView;
        ImageView ivIcon;
        TextView tvTitle;
        TextView tvContent;
        
        ViewHolder(@NonNull View itemView) {
            super(itemView);
            cardView = (MaterialCardView) itemView;
            ivIcon = itemView.findViewById(R.id.iv_icon);
            tvTitle = itemView.findViewById(R.id.tv_title);
            tvContent = itemView.findViewById(R.id.tv_content);
        }
    }
} 